package com.bw.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bw.seriver.OrderInfoSeriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 31629
 * @date 2025年09月03日 9:41
 */
@RestController
public class OrderController {
  @Autowired
    private OrderInfoSeriver orderInfoSeriver;
  //6） sql编写: 按品牌展示每个品牌的销售额  （5分）
  @RequestMapping("s1")
   public JSONObject select1(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONObject data = new JSONObject();
       rest.put("data",data);

      JSONArray categories = new JSONArray();
      data.put("categories",categories);

      List<Map<String, Objects>> maps1 = orderInfoSeriver.select1();
      for (Map<String, Objects> map : maps1) {
          categories.add(map.get("name"));
      }
      JSONArray series = new JSONArray();
      data.put("series",series);

      JSONObject series_row = new JSONObject();
      series_row.put("name","品牌的销售额");
      series.add(series_row);
      JSONArray row = new JSONArray();
      List<Map<String, Objects>> maps = orderInfoSeriver.select1();
      for (Map<String, Objects> map : maps) {
          row.add(map.get("xse"));
          series_row.put("data",row);
      }
      return  rest;
   }
   //7） sql编写: 展示各个品类占总销售额的占比（5分）
   @RequestMapping("s2")
   public JSONObject select2(){
       JSONObject rest = new JSONObject();
       rest.put("status",0);
       rest.put("msg","");
       JSONArray data = new JSONArray();
       rest.put("data",data);

       List<Map<String, Objects>> maps = orderInfoSeriver.select2();
       for (Map<String, Objects> map : maps) {
           JSONObject row = new JSONObject();
           row.put("name",map.get("name"));
           row.put("value",map.get("zb"));
           data.add(row);
       }

       return  rest;
   }

}
